﻿using System;
using System.Collections.Generic;

namespace DesignPatterns.MementoProject
{
    //发起人
    public class MobileOwner
    {
        // 发起人需要保存的内部状态
        private List<ContactPerson> contactPersons;

        public List<ContactPerson> ContactPersons
        {
            get => contactPersons;
            set => contactPersons = value;
        }

        public MobileOwner(List<ContactPerson> contactPersons)
        {
            this.contactPersons = contactPersons;
        }
        // 创建备忘录，将当期要保存的联系人列表导入到备忘录中 
        public ContactMemento CreateMemento()
        {
            return new ContactMemento(new List<ContactPerson>(this.ContactPersons));
            
        }
        
        // 将备忘录中的数据备份导入到联系人列表中
        public void RestoreMemento(ContactMemento memento)
        {
            this.ContactPersons = memento.contactPersonBack;
        }
        
        
        public void Show()
        {
            Console.WriteLine("联系人列表中有{0}个人，他们是:", ContactPersons.Count);
            foreach (ContactPerson p in ContactPersons)
            {
                Console.WriteLine("姓名: {0} 号码为: {1}", p.Name, p.MobileNum);
            }
        }
    }
}